<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script type="text/javascript">
			function jiecheng(){
			var num = parseInt(document.getElementById("inputNumId").value);
			var result = document.getElementById("result");
				if (isNaN(num)) {
					result.innerHTML = "输入的不是数字"
					return;
				}
				if (num == 0) {
					result.innerText = "1";
					return;
				}
				if (num<0) {
					result.innerText = "负数没有阶乘";
					return;
				}else{var sum=1
					for (var i =1;i <= num;i++) {
						sum = sum * i;
					}
					result.innerText= sum;
					return;
				}
			}
		</script>
	</head>
	<body>
		<input type="text" id="inputNumId"/>
		<button onclick="jiecheng()">阶乘</button>=
		<span id="result" ></span>
	</body>
</html>
